import request from '@/utils/request.js'

/**
 * f\发送手机验证码
 * @param {*} mobile 手机号
 * @returns promise
 */
export function getCode (mobile) {
  return request({
    url: '/v1_0/sms/codes/' + mobile
  })
}

/**
 * 登录
 * @param {*} data {mobile,code}
 */
export function login (data) {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}

export function getUsetSelfInfo (token) {
  return request({
    url: '/v1_0/user'
  })
}

export function getUserSelfChannels () {
  return request({
    url: '/v1_0/user/channels'
  })
}

/**
 * 新增列表
 * @param {*} channel {id,seq}
 */
export function addUserChannelItem (channel) {
  return request({
    url: '/v1_0/user/channels',
    method: 'PATCH',
    data: {
      channels: [channel]
    }
  })
}

export function removeUserChannelItem (id) {
  return request({
    url: '/v1_0/user/channels/' + id,
    method: 'DELETE'
  })
}

/**
 * 关注用户
 * @param {*} target 用户ID
 */
export function followArticle (target) {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })
}

/**
 * 取消关注
 * @param {*} target 用户ID
 */
export function deleteArticle (target) {
  return request({
    url: '/v1_0/user/followings/' + target,
    method: 'DELETE'
  })
}

/**
 * 获取用户个人信息
 */
export function getUserProfile () {
  return request({
    url: '/v1_0/user/profile'
  })
}

/**
 * 更新用户信息
 * @param {*} data 更新的用户信息
 */
export function updateUserProfile (data) {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

/**
 * 更新用户头像
 * @param {*} data formData
 */
export function updateUserPhoto (data) {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data
  })
}
